package com.trailwalker.javafx.widget.dialog;

import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;

/**
 * @author Trailwalker
 * @create 2020-07-09 11:41
 * @des
 */
public class BaseDialog {

    private double xOffset = 0;
    private double yOffset = 0;

    protected void setMoveAble(Stage dialogStage, Node dragAblePane) {
        if (dragAblePane != null) {
            dragAblePane.setOnMousePressed(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                    xOffset = event.getSceneX();
                    yOffset = event.getSceneY();
                }
            });

            dragAblePane.setOnMouseDragged(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                    dialogStage.setX(event.getScreenX() - xOffset);
                    dialogStage.setY(event.getScreenY() - yOffset);
                }
            });
        }
    }
}
